<template>
	<view>
		<u-sticky bgColor="#6492FF" offsetTop=0 customNavHeight=0>
			<navbox title="收入记录"></navbox>
			<view class="" style="padding: 25rpx 16rpx;background-color: #f6f6f6;">
				<view class="con__box">
					<view class="con__box__sr">
						<input type="text" v-model="keyword" class="con__box__sr__t" placeholder="输入姓名或项目名称"
							placeholder-style="font-size:26rpx;" />
						<view class="u-flex u-flex-y-center u-flex-between" style="width: 440rpx;">
							<view @click="show=true,datetype=1" class="con__box__sr__t u-flex u-flex-y-center"
								:class="form.beginBuildTime?'c33':''" style="width: 147rpx;">
								{{form.beginBuildTime?form.beginBuildTime:'开始时间'}}
							</view>
							至
							<view @click="show=true,datetype=2" class="con__box__sr__t u-flex u-flex-y-center"
								:class="form.endBuildTime?'c33':''" style="width: 147rpx;">

								{{form.endBuildTime?form.endBuildTime:'截止时间'}}
							</view>
						</view>
					</view>
					<view class="con__box__btn u-flex-xy-center" @click="getlist">
						查询
					</view>
				</view>
			</view>
		</u-sticky>
		<view class="con" v-if="list.length>0">

			<view class="con__item" v-for="(item,index) in list" :key="index">
				<view class="">
					产品：{{item.product}}
				</view>
				<view class="">
					任务：{{item.taskName}}
				</view>
				<view class="">
					金额：{{item.price}}元
				</view>
				<view class="">
					类型：<text v-if="item.type==0">订单【{{item.orderNo}}】</text><text v-if="item.type==1">{{item.childName}}抽成收入</text><text v-if="item.type==2">系统奖励</text>收入
				</view>
				<view class="">
					订单时间：{{item.orderTime}}
				</view>
				<view class="">
					结算时间：{{item.settleTime}}
				</view>
			</view>
		</view>
		<view class="" v-else style="margin-top: 200rpx;">
			<u-empty icon="/static/img/index/empty.png" mode="data" text="暂时没有数据"></u-empty>
		</view>
		<u-datetime-picker :show="show" @confirm="confirm" @cancel="show=false" v-model="value1"
			mode="date"></u-datetime-picker>
	</view>
</template>

<script>
	import {
		incomelist
	} from '@/api/user.js'
	export default {
		data() {
			return {
				list: [],
				keyword: '',
				show: false,
				form: {
					beginBuildTime: '',
					endBuildTime: '',
					childName: '',
					product: ''
				},
				value1: Number(new Date()),
				show: false,
			};
		},
		methods: {
			getlist() {
				this.form.childName = this.keyword
				this.form.product = this.keyword
				let form={
					beginBuildTime:this.form.beginBuildTime?this.form.beginBuildTime+' 00:00:00':'',
					endBuildTime:this.form.endBuildTime?this.form.endBuildTime+' 23:59:59':'',
					childName:this.form.childName,
					product:this.form.product,
					
				}
				incomelist(form).then(res => {
					if (res.data.code == 200) {
						this.list = res.data.data
					}
				})
			},
			confirm(e) {
				if (this.datetype == 1) {
					this.form.beginBuildTime = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
				}
				if (this.datetype == 2) {
					this.form.endBuildTime = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
				}
				this.show = false
			},
			getLastDay() {
				//当前月最后一天
				var y = new Date().getFullYear(); //获取年份
				var m = new Date().getMonth() + 1; //获取月份
				var d = new Date(y, m, 0).getDate(); //获取当月最后一日
				m = m < 10 ? "0" + m : m; //月份补 0
				d = d < 10 ? "0" + d : d; //日数补 0

				return [y, m, d].join("-");
			}
		},
		onLoad(option) {
			if (option.type == 1) { //当日
				this.form.beginBuildTime = uni.$u.timeFormat(Number(new Date()), 'yyyy-mm-dd')
				this.form.endBuildTime = uni.$u.timeFormat(Number(new Date()), 'yyyy-mm-dd')
			}
			if (option.type == 2) { //当月
				this.form.beginBuildTime = uni.$u.timeFormat(Number(new Date()), 'yyyy-mm')+'-01'
				this.form.endBuildTime = this.getLastDay()
				// console.log(this.form.endBuildTime)
			}
			if(option.name){
				this.keyword=option.name
			}
			this.getlist()
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f6f6f6;
	}

	.con {
		padding: 0 16rpx 70rpx;

		&__box {
			background: #FFFFFF;
			border-radius: 14rpx;
			padding: 43rpx 33rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			&__sr {
				width: 440rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: space-between;
				height: 133.33rpx;

				&__t {
					width: 390rpx;
					height: 56rpx;
					border-radius: 28rpx;
					border: 1rpx solid rgba(112, 112, 112, .5);
					padding: 0 25rpx;
					font-family: Source Han Sans SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #707070;
				}
			}

			&__btn {
				width: 133rpx;
				height: 133rpx;
				background: #6492FF;
				border-radius: 7rpx;
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #FFFFFF;
			}
		}

		&__item {
			margin-bottom: 25rpx;
			padding: 24rpx 36rpx;
			line-height: 46rpx;
			font-family: Source Han Sans SC;
			font-weight: 400;
			font-size: 26rpx;
			color: #3E3D3D;
			background: #FFFFFF;
			border-radius: 14rpx;
		}
	}
</style>